package com.saydc.actions.evaluaciones;

import java.io.FileOutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

import com.saydc.forms.evaluaciones.CargaEvaluacionForm;

public class EvaluacionUploadAction extends Action {
	
private static final String FORMULARIOS_PATH = "C:/Users/Mariano/workspace/SAYDC/resources/com/saydc/files/evaluaciones/";
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, 
			HttpServletResponse response) throws Exception {
		
		CargaEvaluacionForm uploadForm = (CargaEvaluacionForm) form;
		FileOutputStream outputStream = null;
		FormFile formFile = null;
		try {
			formFile = uploadForm.getFile();
			/*---para donde esta deployado---*/ 
			//String path = getServlet().getServletContext().getRealPath("")+"/"+formFile.getFileName();
			String path = FORMULARIOS_PATH+formFile.getFileName();
			outputStream = new FileOutputStream(path);
			outputStream.write(formFile.getFileData());
		}
		finally {
			if (outputStream != null) {
				outputStream.close();
			}
		}
		return mapping.findForward("success");
	}

}
